def CDN_DIR = '/srv/dev/react'
pipeline {
    agent any
    
    environment {
        PATH = "/usr/local/maven/bin:$PATH"
        GIT_TOKEN = "hzkvectory"
        GIT_URL = "git@gitee.com:hezk/NettyRpc.git"
    }

    parameters {
        string(name: "node_name", defaultValue: "", description: "jenkins执行节点label")
        string(name: "project_id", defaultValue: "", description: "项目id")
        string(name: "project_name", defaultValue: "", description: "项目名称")
        string(name: "project_type", defaultValue: "", description: "项目类型")
        string(name: "checkout_sha", defaultValue: "", description: "checkout_sha")
    }

    stages {
        stage("start") {
            steps {
                println params
                //sh "build -s progressing"
            }
        }

        stage("checkout code") {
            steps {
                // 按照项目+版本区分
                ws("/opt/build/java2/${project_id}/${checkout_sha}") {
                    git credentialsId: "${GIT_TOKEN}", url: "${GIT_URL}"
                    sh "git checkout --quiet && git status"
                    //sh "git checkout --quiet --detach ${checkout_sha} && git status"
                    //sh "build -s progressing"
                }
            }
        }

        stage("build code") {
            steps {
                ws("/opt/build/java2/${project_id}/${checkout_sha}") {
                    sh "mvn clean package -Dmaven.test.skip=true"
                }
            }
        }
    }


    post {
        success {
            dir("/opt/build/java2/${project_id}/${checkout_sha}") {
                deleteDir()
            }
        }
    }
}
